define(["jquery", "easy-admin", "echarts", "echarts-theme", "miniAdmin"], function ($, ea, echarts, undefined, miniAdmin) {

    var Controller = {
        index: function () {
            var options = {
                iniUrl: ea.url('ajax/initAdmin'),    // 初始化接口
                clearUrl: ea.url("ajax/clearCache"), // 清除缓存接口
                clearApiUrl: ea.url("ajax/clearApiCache"), // 清除接口文档缓存接口
                clearUserUrl: ea.url("ajax/clearUserCache"), // 清除用户登录user-token缓存接口
                getLanguageListUrl: ea.url("ajax/getLanguageList"), // 获取语言切换列表
                switchLanguageUrl: ea.url("ajax/switchLanguage"), // 语言切换
                urlHashLocation: true,      // 是否打开hash定位
                bgColorDefault: false,      // 主题默认配置
                multiModule: true,          // 是否开启多模块
                menuChildOpen: true,       // 是否默认展开菜单
                loadingTime: 0,             // 初始化加载时间
                pageAnim: true,             // iframe窗口动画
                maxTabNum: 20,              // 最大的tab打开数量
            };
            miniAdmin.render(options);

            $('.login-out').on("click", function () {
                ea.request.get({
                    url: 'login/out',
                    prefix: true,
                }, function (res) {
                    ea.msg.success(res.msg, function () {
                        window.location = ea.url('login/index');
                    })
                });
            });
        },
        welcome: function () {
            $.ajax({
                type: "POST",
                url: ea.url('index/getWelcomeData'),
                dataType: 'json',
                data: {},
                success: function (data, status) {
                    var ux = data.ux;
                    var uy = data.uy;

                    /**
                     * 报表功能-用户报表
                     */
                    var userRecords = echarts.init(document.getElementById('user-records'), 'walden');
                    var optionRecords = {
                        title: {
                            text: ''
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['注册量']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ux
                        },
                        yAxis: {
                            type: 'value',
                            minInterval: 1
                        },
                        series: [
                            {
                                name: '注册用户数',
                                type: 'line',
                                stack: '总量',
                                data: uy
                            }
                        ]
                    };
                    userRecords.setOption(optionRecords);
                    // echarts 窗口缩放自适应
                    window.onresize = function(){
                        echartsRecords.resize();
                        userRecords.resize();
                    }
                },
            });
            ea.listen();
        },
        editAdmin: function () {
            ea.listen();
        },
        editPassword: function () {
            ea.listen();
        }
    };
    return Controller;
});
